package cn.bluethink.eguan.rewardtask.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Id;
import javax.persistence.Table;

import cn.bluethink.eguan.model.core.EgOType;
import cn.bluethink.eguan.model.core.EgResult;
import cn.bluethink.eguan.model.core.EgUser;
import cn.bluethink.eguan.model.rewardtask.EgReceiver;
import cn.bluethink.eguan.model.rewardtask.EgRewardTask;

/**
 * 接收者实体模型
 * 
 * @author 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.1.0
 * @note 修订历史： 1、wanglei于2018/10/18设计并构建初始版本v0.1.0
 */
@Table(name = "eg_receiver")
public class EgReceiverEntity implements Serializable {

    private static final long serialVersionUID = -5935042828760521793L;

    @Id
    private Long id;

    // 用户ID
    private Long uid;

    // 任务ID
    private Long tid;

    // 任务当前执行状态
    private Integer status;

    // 任务领取时间
    private Date btime;

    // 任务完成时间
    private Date etime;

    // 任务结果的标识
    private Long resultOid;

    // 奖励的任务赏金
    private Integer reward;

    // 提交时间时间
    private Date subTime;

    public EgReceiverEntity() {

    }

    public EgReceiverEntity(Long id, Long uid, Long tid, Integer status, Integer reward) {
        this.id = id;
        this.uid = uid;
        this.tid = tid;
        this.status = status;
        this.reward = reward;
    }

    /**
     * 业务模型转为实体模型
     * 
     * @param receiver
     */
    public EgReceiverEntity(EgReceiver receiver) {
        this.id = receiver.getId();
        this.uid = receiver.getUser().getId();
        this.tid = receiver.getTask().getId();
        this.status = receiver.getStatus();
        this.btime = receiver.getBtime();
        this.etime = receiver.getEtime();
        this.resultOid = receiver.getResult() == null ? null : receiver.getResult().getId();
        this.reward = receiver.getReward() == null ? 0 : receiver.getReward();
        this.subTime = receiver.getSubTime();
    }

    /*
     * 实体模型转业务模型
     */
    public EgReceiver createEgReceiver() {

        EgReceiver receiver = new EgReceiver();
        receiver.setId(id);
        // 设置接收任务的用户
        receiver.setUser(new EgUser(uid, null, null));
        // 设置领取者所做的悬赏任务
        EgRewardTask task = new EgRewardTask();
        task.setId(tid);
        receiver.setTask(task);

        receiver.setStatus(status);
        receiver.setBtime(btime);
        receiver.setEtime(etime);
        // 设置任务完成的结果
        if (resultOid != null && resultOid > 0) {
            EgResult result = new EgResult(resultOid, null, new EgOType(EgOType.RECEIVER, null));
            receiver.setResult(result);
        }
        if (reward != null && reward > 0) {
            receiver.setReward(reward);
        } else {
            receiver.setReward(0);
        }
        receiver.setSubTime(subTime);
        return receiver;
    }

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public Long getTid() {
        return tid;
    }

    public void setTid(Long tid) {
        this.tid = tid;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getBtime() {
        return btime;
    }

    public void setBtime(Date btime) {
        this.btime = btime;
    }

    public Date getEtime() {
        return etime;
    }

    public void setEtime(Date etime) {
        this.etime = etime;
    }

    public Long getResultOid() {
        return resultOid;
    }

    public void setResultOid(Long resultOid) {
        this.resultOid = resultOid;
    }

    public Integer getReward() {
        return reward;
    }

    public void setReward(Integer reward) {
        this.reward = reward;
    }

    public Date getSubTime() {
        return subTime;
    }

    public void setSubTime(Date subTime) {
        this.subTime = subTime;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}
